package com.cambright.stack.widgets
{
	import com.cambright.lotusroot.Widget;
	import com.cambright.stack.components.MenuComponent;
	
	import flash.display.NativeMenu;
	
	public class DockWidget extends Widget
	{
		private var _icon:$Icon = new $Icon();
		
		private var _menu:MenuComponent;
		private var _menuTarget:NativeMenu;
		
		public function get menu():MenuComponent
		{
			return _menu;
		}
		
		protected function get menuTarget():NativeMenu
		{
			return _menuTarget;
		}
		
		override protected function invoke():void
		{
			_menu = addComponent(MenuComponent);
			_menu.target = _menuTarget = new NativeMenu();
			setMenu();
			_menu.enabled = true;
		}
		
		override protected function enable():void
		{
			_icon.menu = _menuTarget;
		}
		
		override protected function disable():void
		{
			_icon.menu = null;
		}
		
		override protected function dispose():void
		{
			_icon.dispose();
			_icon = null;
			
			removeComponent(_menu);
			_menu = null;
			
			_menuTarget = null;
		}

		protected function setMenu():void
		{
		
		}
		
		public function set tooltip(value:String):void
		{
			_icon.tooltip = value;
		}
		public function get tooltip():String
		{
			return _icon.tooltip;
		}
	}
}
import flash.desktop.DockIcon;
import flash.desktop.InteractiveIcon;
import flash.desktop.NativeApplication;
import flash.desktop.SystemTrayIcon;
import flash.display.NativeMenu;


class $Icon
{
	private var _icon:InteractiveIcon;
	
	private function get _isWindows():Boolean
	{
		return _icon is SystemTrayIcon;
	}
	
	private function get _trayIcon():SystemTrayIcon
	{
		return _icon as SystemTrayIcon;
	}
	
	private function get _dockIcon():DockIcon
	{
		return _icon as DockIcon;
	}
	
	public function $Icon()
	{
		_icon = NativeApplication.nativeApplication.icon;
	}
	
	public function get menu():NativeMenu
	{
		return _icon["menu"];
	}
	public function set menu(value:NativeMenu):void
	{
		_icon["menu"] = value;
	}
	
	public function get tooltip():String
	{
		if(_isWindows) return _trayIcon.tooltip;
		return null;
	}
	public function set tooltip(value:String):void
	{
		if(_isWindows) _trayIcon.tooltip = value;
	}
	
	public function dispose():void
	{
		_icon = null;
	}
}


